unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, JvTFManager, JvExControls, JvTFGlance, JvTFMonths,
  JvTFGlanceTextViewer, DateUtils, JvTFDays, JvTFWeeks;

type
  TForm1 = class(TForm)
    JvTFMonths1: TJvTFMonths;
    JvTFScheduleManager1: TJvTFScheduleManager;
    Button1: TButton;
    JvTFDays1: TJvTFDays;
    Button2: TButton;
    JvTFGlanceTextViewer1: TJvTFGlanceTextViewer;
    JvTFGlanceTextViewer2: TJvTFGlanceTextViewer;
    JvTFWeeks1: TJvTFWeeks;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure JvTFScheduleManager1LoadBatch(Sender: TObject; BatchName: string;
      BatchStartDate, BatchEndDate: TDate);
    procedure Button2Click(Sender: TObject);
    procedure JvTFScheduleManager1PostAppt(Sender: TObject; Appt: TJvTFAppt);
    procedure JvTFMonths1DblClick(Sender: TObject);
    procedure JvTFMonths1DropAppt(Sender: TObject; Appt: TJvTFAppt;
      var NewStartDate, NewEndDate: TDate; var Confirm: Boolean);
    procedure JvTFGlanceTextViewer1DblClick(Sender: TObject);
  private
    { Private declarations }
  public
    Appt : TJvTFAppt;
    New : Boolean;
    vAppt : TJvTFAppt;
    { Public declarations }
  end;

var
  Form1: TForm1;
  ListaSched : TStringList;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var

 vDt : TDate;
 vHr : TTime;
 i : Integer;
begin
  Appt := JvTFDays1.ScheduleManager.dbNewAppt('');
  //Appt.Persistent := True;
  Appt.BeginUpdate;
  Appt.SetStartEnd(Date,Time,Date,IncHour(Time));
  //Appt.BeginUpdate;
  Appt.Description := 'teste teste';
  for i := 0 to JvTFDays1.Cols.Count - 1 do
  begin
    Appt.AddSchedule(JvTFDays1.Cols[i].SchedName);
    ShowMessage(JvTFDays1.Cols[i].SchedName);
  end;
  //Appt.Persistent := False;
  Appt.EndUpdate;
end;

procedure TForm1.Button2Click(Sender: TObject);
var i : Integer;
begin
{  JvTFMonths1.Year := 2014;
  JvTFMonths1.Month := 4;}
  for i := 0 to JvTFScheduleManager1.ApptCount - 1 do
  begin
    JvTFScheduleManager1.Appts[i].Delete;
  end;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  JvTFMonths1.SchedNames.Clear;
  JvTFMonths1.SchedNames.Add('GLAUCOS');
  JvTFMonths1.Refresh;
  JvTFWeeks1.SchedNames.Clear;
  JvTFWeeks1.SchedNames.Add('GLAUCOS');
  JvTFWeeks1.Refresh;
end;

procedure TForm1.JvTFGlanceTextViewer1DblClick(Sender: TObject);
begin
  Appt := JvTFGlanceTextViewer1.SelAppt;
  ShowMessage(Appt.ID);
end;

procedure TForm1.JvTFMonths1DblClick(Sender: TObject);
var p : TPoint;
    m : TMouse;
begin
  m := TMouse.Create;
  m.Capture := JvTFMonths1.Handle;
  ShowMessage(IntToStr(m.CursorPos.X) + ' - ' + IntToStr(m.CursorPos.Y));
  {vAppt := JvTFMonths1.Viewer.GetApptAt(p.X,p.Y);
  if Assigned(vAppt) then
  begin
    ShowMessage(vAppt.Description);
    vAppt.Free;
  end;


  ShowMessage(IntToStr(p.x) + ' ' + IntToStr(p.Y));}
  m.Free;
end;

procedure TForm1.JvTFMonths1DropAppt(Sender: TObject; Appt: TJvTFAppt;
  var NewStartDate, NewEndDate: TDate; var Confirm: Boolean);
begin
  Confirm := false;
end;

procedure TForm1.JvTFScheduleManager1LoadBatch(Sender: TObject;
  BatchName: string; BatchStartDate, BatchEndDate: TDate);
begin
//  ShowMessage('OI');
//  ShowMessage(DateToStr(BatchStartDate));
end;

procedure TForm1.JvTFScheduleManager1PostAppt(Sender: TObject; Appt: TJvTFAppt);
begin
  ShowMessage('post');
end;

end.
